
package com.punch.common.feign.fallback;


import com.punch.common.feign.FeignUserService;
import com.punch.common.model.LoginUser;
import com.punch.common.model.Result;
import com.punch.common.vo.user.user.UserExtendVO;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;


/**
 * userService降级工场
 *
 * @author zlt
 * @date 2019/1/18
 */

@Slf4j
@Component
public class FeignUserServiceFallbackFactory implements FallbackFactory<FeignUserService> {
    @Override
    public FeignUserService create(Throwable throwable) {
        return new FeignUserService() {


            /**
             * 通过手机号查询用户、角色信息
             *
             * @param mobile 手机号
             */
            @Override
            public LoginUser getUserByMobile(String mobile) {
                log.error("通过手机号查询用户异常:{}", mobile, throwable);
                return new LoginUser();
            }

            /**
             * 获取用户结算信息
             *
             * @param userId 用户id
             * @param type 类型
             * @return long
             */
            @Override
            public Result<UserExtendVO> getUserSettlement(Long userId, Integer type) {
                log.error("获取用户结算信息异常:{}", userId, throwable);
                return Result.failed("类型错误", 9999);
            }
        };
    }
}

